home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / Creator Changer 1.0.3 / Code and Resource / Creator Changer.start.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-14  |  5.7 KB  |  234 lines  |  [TEXT/KAHL]

  1. /**********************************************************************
  2.  *    This file contains the functions which start off the program.  The
  3.  *    main event loop and Macintosh toolbox definitions are in this
  4.  *    file.
  5.  **********************************************************************/
  6.  
  7. #include "Creator Changer.h"
  8. #include "Creator Changer.start.h"
  9.  
  10.  
  11.  
  12. /**********************************************************************
  13.  *    Function main(), this is the main function of the program.  The 
  14.  *    major parts of the program are called in this function.
  15.  **********************************************************************/
  16.  
  17. void main(void)
  18.     {
  19.     
  20.     Init_Toolbox();
  21.     Set_Up_Menu_Bar();
  22.     //  Check_Sys_Type();
  23.     Main_Event_Loop();
  24.  
  25.     }
  26.  
  27.  
  28.  
  29. /**********************************************************************
  30.  *    Function Init_Toolbox(), this function initializes the Macintosh 
  31.  *    toolbox so that all of the parts of the program will work.
  32.  **********************************************************************/
  33.  
  34. void Init_Toolbox(void)
  35.     {
  36.     
  37.     InitGraf(&thePort);
  38.     InitFonts();
  39.     InitWindows();
  40.     InitMenus();
  41.     FlushEvents(everyEvent, REMOVE_EVENTS);
  42.     TEInit();
  43.     InitDialogs(NIL_PTR);
  44.     InitCursor();
  45.     MaxApplZone();
  46.     
  47.     MoreMasters();
  48.     MoreMasters();
  49.     MoreMasters();
  50.     
  51.     }
  52.  
  53.  
  54.  
  55. /**********************************************************************
  56.  *    Function Set_Up_Menu_Bar(), this function displays the menu bar
  57.  *    for the program. 
  58.  **********************************************************************/
  59.  
  60. void Set_Up_Menu_Bar(void)
  61.     {
  62.     
  63.     SetMenuBar(GetNewMBar(MAIN_MENU_BAR_ID));
  64.     Apple_Menu=GetMHandle(APPLE_MENU_ID);
  65.     AddResMenu(Apple_Menu, 'DRVR');
  66.     Options_Menu=GetMHandle(OPTIONS_MENU_ID);
  67.     DrawMenuBar();
  68.     
  69.     }
  70.  
  71.  
  72. /*  I commented this block out because I think I found out why the 
  73.  *  program would not work on System 6.  I really think that it was
  74.  *  just a fluke problem that happened on that computer, but I am not 
  75.  *  sure, as I do not have acess to a System 6 machine anymore.
  76.  */
  77. /**********************************************************************
  78.  *    Function Check_Sys_Type(), this function checks to see if System
  79.  *    seven or later is present, if it isn't then the program quits.
  80.  **********************************************************************/
  81. /*
  82. void Check_Sys_Type(void)
  83.     {
  84.     
  85.     short        sys_7=0x0700;        //    hexadecimal value for system seven.
  86.     short        vers_requsted=1;    //    I just know this gives me what I want.
  87.     SysEnvRec    the_environ;
  88.     
  89.     SysEnvirons(vers_requsted, &the_environ);
  90.     
  91.     if(the_environ.systemVersion>=sys_7) All_Done=FALSE;
  92.     else
  93.         {
  94.         ParamText("\pSystem 7 or later is required!!", "\p", "\p  Sorry!", "\p");
  95.         Alert(ERROR_ALERT, NIL_PTR);
  96.         All_Done=TRUE;
  97.         }
  98.     
  99.     }
  100. */
  101.  
  102.  
  103.  
  104. /**********************************************************************
  105.  *    Function Main_Event_Loop(), this function sets up the main event
  106.  *    loop.  This function also cheks to see if multifinder is active.
  107.  **********************************************************************/
  108.  
  109. void Main_Event_Loop(void)
  110.     {    
  111.         //    I have no clue how this works, but it does determine if ...
  112.         //    ... multifinder is active or not.
  113.     Multifinder_Active=(NGetTrapAddress(WNE_TRAP_NUM, ToolTrap)!=
  114.                         NGetTrapAddress(UNIMPL_TRAP_NUM, ToolTrap));
  115.         //    Open the "Open Dialog" box at start-up
  116.     Handle_Options_Choice(O_OPEN_ITEM);
  117.         //    The MainEvent loop
  118.     while(All_Done==FALSE) Handle_One_Event();
  119.     
  120.     }
  121.  
  122.  
  123.  
  124. /**********************************************************************
  125.  *    Function Handle_One_Event(), this function handles one event.  
  126.  *    Depending on what the event is, it gets directed to the 
  127.  *    appropriate place.
  128.  **********************************************************************/
  129.  
  130. void Handle_One_Event(void) 
  131.     {
  132.     
  133.     if(Multifinder_Active==TRUE)
  134.         WaitNextEvent(everyEvent, &The_Event, SLEEP_TICKS, MOUSE_REGION);
  135.     else
  136.         {
  137.         SystemTask();
  138.         GetNextEvent(everyEvent, &The_Event);
  139.         }
  140.     switch(The_Event.what)
  141.         {
  142.         case mouseDown: 
  143.             Handle_Mouse_Down();
  144.             break;
  145.         case keyDown:
  146.         case autoKey:
  147.             Handle_Auto_Key();
  148.             break;
  149.         }
  150.     
  151.     }
  152.  
  153.  
  154.  
  155. /**********************************************************************
  156.  *    Function Handle_Mouse_Down(), this function handles any mouse down
  157.  *    event, such as a window select, in the menu bar etc.
  158.  **********************************************************************/
  159.  
  160. void Handle_Mouse_Down(void)
  161.     {
  162.     
  163.     WindowPtr    which_window;
  164.     short        the_part;
  165.     long        menu_choice;
  166.  
  167.     the_part=FindWindow(The_Event.where, &which_window);  
  168.     
  169.     switch(the_part)
  170.         {
  171.         case inMenuBar:
  172.             menu_choice=MenuSelect(The_Event.where);
  173.             Handle_Menu_Choice(menu_choice);              
  174.             break;
  175.         case inSysWindow: 
  176.             SystemClick(&The_Event, which_window);
  177.             break;
  178.         case inContent:
  179.             SelectWindow(which_window);
  180.             break;
  181.         }
  182.  
  183.     }
  184.  
  185.  
  186.  
  187. /**********************************************************************
  188.  *    Function Handle_Auto_Key(), this function handles command key 
  189.  *    events for the menu items.
  190.  **********************************************************************/
  191.  
  192. void Handle_Auto_Key(void)
  193.     {
  194.     
  195.     register char command_key;    
  196.             
  197.     command_key=The_Event.message;
  198.     if(The_Event.modifiers!=0) Handle_Menu_Choice(MenuKey(command_key));
  199.     
  200.     }
  201.  
  202.  
  203.  
  204. /**********************************************************************
  205.  *    Function Handle_Menu_Choice(), this function handles the menu 
  206.  *    choice made, then it directs it to the appropriate place.
  207.  **********************************************************************/
  208.  
  209. void Handle_Menu_Choice(long menu_choice)
  210.     {
  211.     
  212.     int the_menu;
  213.     int the_menu_item;
  214.     
  215.     if(menu_choice!=0)
  216.         {
  217.         the_menu=HiWord(menu_choice);
  218.         the_menu_item=LoWord(menu_choice);
  219.         
  220.         switch(the_menu)
  221.             {
  222.             case APPLE_MENU_ID:
  223.                 Handle_Apple_Choice(the_menu_item);
  224.                 break;
  225.             case OPTIONS_MENU_ID:
  226.                 Handle_Options_Choice(the_menu_item);
  227.                 break;
  228.             defualt:
  229.                 break;
  230.             }
  231.         HiliteMenu(0);
  232.         }
  233.     
  234.     }